    $(document).ready(function() {
        var map, trafficLayer, satellite;
        initMap();
        area3DBoundary();
        Judgeidentity();
        statusCurMsg()

    })


    //地图初始化
    function initMap() {
        streetCode = 0;
        $('#panel').html('')
        $("input[type='radio']").each(function() {
            this.checked = false;
        });
        $("input[type='checkbox']").each(function() {
            this.checked = false;
        });
        map = new AMap.Map('map', {
            viewMode: '3D',
            zoom: 12,
            expandZoomRange: true,
            buildingAnimation: true, //楼块出现是否带动画
            zooms: [3, 20],
            rotation: 8,
            pitch: 50,
            center: [118.978548, 32.132001],
            //center: [119.310012,32.204719],
            features: ['bg', 'road', 'building', 'point'],
            layers: [
                // 高德默认标准图层
                // 楼块图层
                new AMap.Buildings({
                    zooms: [3, 18],
                    zIndex: 10,
                    heightFactor: 3 //2倍于默认高度，3D下有效
                }),
            ],
            mapStyle: 'amap://styles/6f2ac55a0fce7bb44145e64373f74f99',
            //mapStyle: 'amap://styles/1a24a12d3d9c248734e7129c07411fad',
        });

        /**/
        /**/
        // 创建Object3DLayer图层
        /*        var object3Dlayer1 = new AMap.Object3DLayer();
                map.add(object3Dlayer1);

                map.plugin(["AMap.GltfLoader"], function() {

                    var firehouse = {
                        position: new AMap.LngLat(119.309553,32.203258), // 必须
                        scale: 0.05, // 非必须，默认1
                        height: 0, // 非必须，默认0
                        scene: 0, // 非必须，默认0
                    };
                    var city = {
                        position: new AMap.LngLat(119.309121,32.203375), // 必须
                        scale: 0.1, // 非必须，默认1
                        height: 0, // 非必须，默认0
                        scene: 0, // 非必须，默认0
                    };
                    var gltfObj = new AMap.GltfLoader();

                    gltfObj.load('../static/GJson/firehouse.gltf', function(gltf) {
                        gltf.setOption(firehouse);
                        gltf.rotateZ(-20);
                        object3Dlayer1.add(gltf);
                    });
                    gltfObj.load('../static/GJson/city1.gltf', function(gltf) {
                        gltf.setOption(city);
                        gltf.rotateY(-20);
                        gltf.rotateX(90);
                        object3Dlayer1.add(gltf);
                    });

                });*/

        /**/
        /**/


        trafficLayer = new AMap.TileLayer.Traffic({
            zIndex: 10
        });
        trafficLayer.setMap(map);
        trafficLayer.hide();


        satellite = new AMap.TileLayer.Satellite({
            map: map,
        });
        satellite.setMap(map);
        satellite.hide();
        /*单击地图事件*/
        map.on('click', function(e) {
            infoWindow.close();
            console.log(e.lnglat.getLng() + ',' + e.lnglat.getLat())
        });
        /*层级改变事件*/
        map.on('zoomchange', function(e) {
            judgeWithZoom()
        });

        /*    map.on('zoomend', function(e) {
                clearStreet3DBoundary()
            });*/

        AMapUI.loadUI(['control/BasicControl'], function(BasicControl) {
            //图层切换控件
            map.addControl(new BasicControl.LayerSwitcher({
                position: 'rb'
            }));
        });

        AMap.plugin('AMap.Weather', function() {
            var weather = new AMap.Weather();
            //查询实时天气信息, 查询的城市到行政级别的城市，如朝阳区、杭州市
            weather.getLive('栖霞区', function(err, data) {
                if (!err) {
                    //获取温度
                    $("#temperature").html("当前" + data.temperature + "℃");
                    //获取天气
                    $("#weather").html("天气：" + data.weather);
                }
            });
        });

    }

    /*重置首页地图*/
    $('#resetMap').click(function() {
        map.destroy();
        initMap()
        area3DBoundary()
    })

    var object3Dlayer;
    //圈出行政区域立体边界
    function area3DBoundary() {
        if (Polygon != undefined) {
            map.remove(Polygon);
        }
        map.remove(streetMarkers);
        // 设置光照
        map.AmbientLight = new AMap.Lights.AmbientLight([1, 1, 1], 0.5);
        map.DirectionLight = new AMap.Lights.DirectionLight([0, 0, 1], [1, 1, 1], 1);
        qiXia3DBoundary()

        //
        streetNodeNumber()
    }

    function qiXia3DBoundary() {
        clearStreet3DBoundary()
        object3Dlayer = new AMap.Object3DLayer();
        map.add(object3Dlayer);

        new AMap.DistrictSearch({
            subdistrict: 2, //返回下一级行政区
            extensions: 'all', //返回行政区边界坐标组等具体信息
            level: 'district' //查询行政级别
        }).search('栖霞区', function(status, result) {
            var bounds = result.districtList[0].boundaries;
            var height = 5000;
            var color = 'rgba(35, 124, 174,0.5)'; // rgba
            var prism = new AMap.Object3D.Prism({
                path: bounds,
                height: height,
                color: color
            });

            prism.transparent = true;
            object3Dlayer.add(prism);

        });
    }

    /*按街道划分设备数量*/
    var streetMarkers = [];

    function streetNodeNumber() {
        var streetArr = {
            "尧化街道": {
                "po": [118.882574, 32.122149],
                "value": "186",
                "key": "yh",
                "code": "320113001",
                "name": "尧化街道"
            },
            "马群街道": {
                "po": [118.891601, 32.049522],
                "value": "186",
                "key": "mq",
                "code": "320113002",
                "name": "马群街道"
            },
            "迈皋桥街道": {
                "po": [118.827274, 32.111995],
                "value": "186",
                "key": "mgq",
                "code": "320113003",
                "name": "迈皋桥街道"
            },
            "燕子矶街道": {
                "po": [118.843939, 32.140956],
                "value": "186",
                "key": "yzj",
                "code": "320113004",
                "name": "燕子矶街道"
            },
            "栖霞街道": {
                "po": [118.952702, 32.152095],
                "value": "186",
                "key": "qx",
                "code": "320113005",
                "name": "栖霞街道"
            },
            "龙潭街道": {
                "po": [119.123618, 32.219791],
                "value": "186",
                "key": "lt",
                "code": "320113006",
                "name": "龙潭街道"
            },
            "仙林街道": {
                "po": [118.921384, 32.099123],
                "value": "186",
                "key": "xl",
                "code": "320113007",
                "name": "仙林街道"
            },
            "西岗街道": {
                "po": [119.002301, 32.156414],
                "value": "186",
                "key": "xg",
                "code": "320113010",
                "name": "西岗街道"
            },
            "八卦洲街道": {
                "po": [118.808658, 32.192729],
                "value": "186",
                "key": "bgz",
                "code": "320113009",
                "name": "八卦洲街道"
            },
        }
        streetMarkers = [];
        $.each(streetArr, function(index, el) {
            /*onmouseenter="street3DBoundary('${el.name}')" onmouseleave="clearStreet3DBoundary()"*/
            var streetMarkerContent = `
                <div id="streetMarker"   onclick="townshipBoundary('${el.name}', '${el.key}', '${el.code}')">
                <p>${el.name}</p>
                <p>${el.value}</p>
                </div>
                `;
            var streetMarker = new AMap.Marker({
                position: new AMap.LngLat(el.po[0], el.po[1]),
                // 将 html 传给 content
                content: streetMarkerContent,
                anchor: 'center',
                // 以 icon 的 [center bottom] 为原点
                offset: new AMap.Pixel(5, -13)
            });
            streetMarkers.push(streetMarker)

            // 将 markers 添加到地图
            map.add(streetMarker);

        });
    }

    //圈出街道
    var Polygon;
    var streetKey = 'all';
    var streetCode = 0;

    function townshipBoundary(streetname, namekey, code) {
        isCollect = 2;
        infoWindow.close();
        map.remove(map.getAllOverlays('polyline'));
        if (exerciseGroups != undefined) {
            map.remove(exerciseGroups);
        }
        if (fireMarker != undefined) {
            map.remove(fireMarker);
        }
        if (carMarker != undefined) {
            map.remove(carMarker);
        }

        if (driving != undefined) {
            driving.clear()
        }
        if (circle != undefined) {
            map.remove(circle);
        }
        streetKey = namekey
        if (Polygon != undefined) {
            map.remove(Polygon);
        }
        if (object3Dlayer != undefined) {
            map.remove(object3Dlayer);
        }


        if (streetname == '全区') {
            streetCode = 0;
            area3DBoundary()
            map.setZoom(12);
            map.setCenter([118.987548, 32.132001]);
        } else {
            ajax('../static/GJson/栖霞区.json', function(err, geoJSON) {
                if (!err) {
                    var geojson = new AMap.GeoJSON({
                        geoJSON: geoJSON,
                        getPolygon: function(geojson, lnglats) {
                            if (geojson.properties.name == streetname) {
                                streetCode = code;
                                judgeWithZoom();
                                /*     var xksjd = [];
                                     $.each(lnglats[0], function(index, el) {
                                         var jds = [];
                                         jds.push(GPS.gcj_encrypt(el[0], el[1]).lng);
                                         jds.push(GPS.gcj_encrypt(el[0], el[1]).lat);

                                         xksjd.push(jds)
                                     })
                                     console.log(xksjd)*/
                                /*var outer = [
                                    new AMap.LngLat(-360, 90, true),
                                    new AMap.LngLat(-360, -90, true),
                                    new AMap.LngLat(360, -90, true),
                                    new AMap.LngLat(360, 90, true),
                                ];
                                var holes = lnglats

                                var pathArray = [
                                    outer
                                ];
                                pathArray.push.apply(pathArray, holes);*/
                                Polygon = new AMap.Polygon({
                                    path: lnglats,
                                    fillOpacity: 0.01,
                                    fillColor: '#' + Math.floor(Math.random() * 16777215).toString(16),
                                    strokeColor: '#aecc1c',
                                    strokeWeight: 5,
                                    strokeOpacity: 0.9,
                                });
                                let mybounds = new AMap.Bounds([Polygon.getBounds().northeast.lng, Polygon.getBounds().northeast.lat], [Polygon.getBounds().southwest.lng, Polygon.getBounds().southwest.lat]);
                                map.setBounds(mybounds)
                                return Polygon
                            }
                        }
                    });
                    // map.setFitView();
                    geojson.setMap(map);
                } else {

                }
            })
        }


    }

    /*地图添加覆盖物*/

    var overlayGroups = new Object();

    function setIconIntoMap(item) {
        map.remove(streetMarkers);
        var markers = [];
        ajax('../static/GJson/point.json', function(err, geoJSON) {
            /*if (streetKey == 'all') {*/
            $.each(geoJSON[item].coordinates, function(index, el) {
                $.each(el, function(index, el) {
                    // 创建点实例
                    var marker = new AMap.Marker({
                        position: new AMap.LngLat(el[0], el[1]),
                        icon: '../static/img/' + geoJSON[item].icon,
                    });

                    createInfoWindow(marker, item, 'nofire', geoJSON[item].type);

                    markers.push(marker);
                });
            });
            /*  } else {

              }*/
            overlayGroups[item] = new AMap.OverlayGroup(markers);
            map.add(overlayGroups[item]);
        })

    }


    /*清除marker*/

    function clearIconIntoMap(item) {
        infoWindow.close();
        map.remove(overlayGroups[item]);
    }


    /*模拟报警*/
    $('#exercise').click(function() {
        isCollect = 0;
        analogAlarm()
    })
    var infoWindow = new AMap.InfoWindow({
        offset: new AMap.Pixel(12, -30),
        //closeWhenClickMap: true
    });
    var fireMarker;

    function analogAlarm() {
        if (Polygon != undefined) {
            map.remove(Polygon);
        }
        if (object3Dlayer != undefined) {
            map.remove(object3Dlayer);
        }
        $('.header-content-bottom-left-item').slideUp();
        $('.header-content-bottom-right-item').slideUp();
        clearMapInfo();

        fireMarker = new AMap.Marker({
            map: map,
            position: [118.882017, 32.046384],
            icon: '../static/img/fire.png',
            offset: new AMap.Pixel(-32, -50)
        });
        fireMarker.setMap(map);
        map.setFitView();

        fireMarker.content = `<div style="width:4rem;height:2.8rem;">
    <div class="info-window-tit" style="color: #fa3c2b;">
        <img src="../static/img/exercise.png">
        发现火情！
    </div>
    <div class="info-window-con">
        <ul style="margin-top: 0.1rem;">
            <li class="info-window-li">
                <div>报警地点</div>
                <div>钟山紫郡13栋</div>
            </li>
            <li class="info-window-li">
                <div>报警时间</div>
                <div>2017-10-13 13:44:55</div>
            </li>
        </ul>
    </div>
    <div class="info-window-tit" style="color: #ffb41e;">
        <img src="../static/img/save.png">
        紧急救援
    </div>
    <div id="radius">
        <div id="radius1" onclick="setRadius(3)"></div>
        <div id="radius2" onclick="setRadius(2)"></div>
        <div id="radius3" onclick="setRadius(1)"></div>
        <span>2KM</span>
        <span>5KM</span>
        <span>10KM</span>
        <img src="../static/img/firepe.png">
        <div id="radiusmsg">
            <p>选择右侧半径范围</p>
            <p>立即查找附近<span id="radiusrange">2KM</span></p>
            <p>的消防设施</p>
        </div>
        <div id="radiusbutton" onclick="searchFacilities()">查找</div>
    </div>
</div>`;
        fireMarker.on('click', function(e) {
            radiusFlag = 1;
            infoWindow.setContent(e.target.content);
            infoWindow.open(map, e.target.getPosition());
            map.setFitView();
        });


    }


    /*模拟驾驶路线*/
    var carMarker, passedPolyline, carPolyline, driving;

    function drivingRoutes(lng, lat, type, cartype) {
        if (cartype == 'jhc') {
            var img = 'jhc.png';
        } else if (cartype == 'gcc') {
            var img = 'gcc.png';
        } else if (cartype == 'xfc') {
            var img = 'xfcl.png';
        } else if (cartype == 'txc') {
            var img = 'txc.png';
        }
        infoWindow.close();
        $('#panel').html('');
        var lineArr = [];
        //构造路线导航类
        driving = new AMap.Driving({
            map: map,
            panel: "panel"
        });
        // 根据起终点经纬度规划驾车导航路线
        driving.search(new AMap.LngLat(lng, lat), new AMap.LngLat(118.882017, 32.046384), function(status, result) {
            /*获取坐标集合*/
            $.each(result.routes[0].steps, function(index, item) {
                $.each(item.path, function(index, item) {
                    var _location = [];
                    _location.push(item.lng)
                    _location.push(item.lat)
                    lineArr.push(_location)
                })

                /*  var start_location = [];
                    var end_location = [];
                    start_location.push(item.start_location.lng)
                    start_location.push(item.start_location.lat)
                    end_location.push(item.end_location.lng)
                    end_location.push(item.end_location.lat)
                    lineArr.push(start_location)
                    lineArr.push(end_location)*/
            })

            /*绘制动态效果*/
            carMarker = new AMap.Marker({
                map: map,
                position: [lng, lat],
                icon: '../static/img/' + img,
                offset: new AMap.Pixel(-26, -13),
                autoRotation: true,
                angle: -90,
            });

            // 绘制轨迹
            carPolyline = new AMap.Polyline({
                map: map,
                path: lineArr,
                showDir: true,
                strokeColor: "#28F", //线颜色
                // strokeOpacity: 1,     //线透明度
                strokeWeight: 6, //线宽
                // strokeStyle: "solid"  //线样式
            });

            passedPolyline = new AMap.Polyline({
                map: map,
                // path: lineArr,
                strokeColor: "#AF5", //线颜色
                // strokeOpacity: 1,     //线透明度
                strokeWeight: 6, //线宽
                // strokeStyle: "solid"  //线样式
            });


            carMarker.on('moving', function(e) {
                passedPolyline.setPath(e.passedPath);
            });

            if (type == 'auto') {
                map.setFitView([circle]);

            }
            carMarker.moveAlong(lineArr, 1000);
            $(".amap-call").after(`<div class='amap-tit'>
                                     <p>已为您规划最优路线</p>
                                     <p>跟车消防员：肖房</p>
                                     <p>联系方式：18546215626</p>
                                     <p>一键呼叫：<img style="width: 0.24rem;height: 0.24rem;cursor: pointer;" src="../static/img/phone.png"></p>
                                     <p>车牌号：苏·X0202应急</p>
                                     <span>
                                        <img src="../static/img/close.png" onclick="$('#panel').html('')">
                                     </span>
                                    </div>`);

        });

    }

    /**/
    var radiusFlag = 1;

    function setRadius(type) {
        radiusFlag = type;
        if (type == 1) {
            $('#radiusrange').html('2KM');
            $('#radius3').css('opacity', '1');
            $('#radius2').css('opacity', '0.7');
            $('#radius1').css('opacity', '0.8');

        } else if (type == 2) {
            $('#radiusrange').html('5KM');
            $('#radius2').css('opacity', '1');
            $('#radius1').css('opacity', '0.8');
            $('#radius3').css('opacity', '0.6');

        } else if (type == 3) {
            $('#radiusrange').html('10KM');
            $('#radius1').css('opacity', '1');
            $('#radius2').css('opacity', '0.7');
            $('#radius3').css('opacity', '0.6');

        }

    }
    var circle;
    var exerciseGroups;

    function searchFacilities() {
        infoWindow.close();
        map.remove(map.getAllOverlays('polyline'));
        if (exerciseGroups != undefined) {
            map.remove(exerciseGroups);
        }
        if (carMarker != undefined) {
            map.remove(carMarker);
        }

        if (driving != undefined) {
            driving.clear()
        }
        if (circle != undefined) {
            map.remove(circle);
        }
        if (radiusFlag == 1) {
            var radius = 2000;
            var item = 'near';

        } else if (radiusFlag == 2) {
            var radius = 5000;
            var item = 'middle';
        } else if (radiusFlag == 3) {
            var radius = 10000;
            var item = 'far';
        }

        circle = new AMap.Circle({
            center: [118.882017, 32.046384],
            radius: radius,
            borderWeight: 3,
            strokeColor: "#FF33FF",
            strokeOpacity: 1,
            strokeWeight: 3,
            strokeOpacity: 0.4,
            fillOpacity: 0.1,
            strokeStyle: 'dashed',
            strokeDasharray: [5, 5],
            fillColor: '#1791fc',
            zIndex: 50,
        })
        circle.setMap(map);


        var markers = [];
        ajax('../static/GJson/exercise.json', function(err, geoJSON) {
            $.each(geoJSON[item], function(index, el) {
                // 创建点实例
                var marker = new AMap.Marker({
                    position: new AMap.LngLat(el.coordinate[0], el.coordinate[1]),
                    icon: '../static/img/' + el.icon,
                });
                if (el.type == 'xfc' || el.type == 'jhc' || el.type == 'gcc' || el.type == 'txc') {
                    marker.on('click', function(e) {
                        drivingRoutes(el.coordinate[0], el.coordinate[1], 'no', el.type);
                    });
                } else {
                    createInfoWindow(marker, el.type, 'fire')
                }
                markers.push(marker);
            });
            exerciseGroups = new AMap.OverlayGroup(markers);
            map.add(exerciseGroups);
        })


        /*        drivingRoutes(118.875287, 32.059401, 'auto', 'jhc');
                drivingRoutes(118.868041, 32.03845, 'auto', 'gcc');
                drivingRoutes(118.89547, 32.04847, 'auto', 'txc');*/
        drivingRoutes(118.892966, 32.036065, 'auto', 'xfc');

    }


    /*创建信息窗体*/

    function createInfoWindow(marker, item, type, name) {
        if (item == 'spjk') {
            marker.content = `<div style="width:3.2rem;height:2.8rem;">
                                  <div class="info-window-tit">
                                       <img src="../static/img/jiank.png">
                                    视频监控
                                   </div>
                                   <div  class="info-window-con" style="margin-top:0.2rem;">
                                      <video style="width:100%; heigh:100%; object-fit: fill"  controls autoplay loop>
                                         <source src="../static/img/${type}.mp4" type="video/mp4">
                                        您的浏览器不支持在线视频格式。
                                    </video>
                                  </div>
                                   <div style="color: #fff;font-size: 0.12rem;margin: 0.2rem 0 0 0.2rem;">地址：钟山紫郡门卫旁雨棚</div>
                              </div>`;

        } else if (item == 'xfz') {
            marker.content = `<div style="width:3.4rem;height:2.3rem;">
                                            <div class="info-window-tit">
                                                <img src="../static/img/xfz.png">
                                                消防站信息
                                            </div>
                                            <div class="info-window-con">
                                                <ul style="margin-top: 0.1rem;">
                                                    <li class="info-window-li">
                                                        <div>站点</div>
                                                        <div>栖霞消防中队</div>
                                                    </li>
                                                    <li class="info-window-li">
                                                        <div>地址</div>
                                                        <div>羊山北路6号</div>
                                                    </li>
                                                    <li class="info-window-li">
                                                        <div>消防员</div>
                                                        <div>18人</div>
                                                    </li>
                                                    <li class="info-window-li">
                                                        <div>消防车</div>
                                                        <div>3辆</div>
                                                    </li>
                                                    <li class="info-window-li">
                                                        <div>联系方式</div>
                                                        <div>18965478954</div>
                                                    </li>
                                                    <li class="info-window-li">
                                                        <div>一键呼叫</div>
                                                        <div><img style="width: 0.24rem;height: 0.24rem;cursor: pointer;" src="../static/img/phone.png"></div>
                                                    </li>

                                                </ul>
                                            </div>
                                        </div>`;


        } else if (item == 'xfc') {
            marker.content = `<div style="width:4.5rem;height:2.4rem;">
                                <div class="info-window-tit">
                                       <img src="../static/img/xfc.png">
                                       消防车信息
                                   </div>
                                <div class="info-window-con" style="display: flex;">
                                       <div>
                                            <img src="../static/img/cardemo.jpg" style="margin-top: 0.14rem;">
                                     </div>
                                     <ul style="margin-top: 0.1rem;width: 2rem;margin-left: 0.16rem;">
                                        <li class="info-window-li">
                                             <div class="info-window-car">车牌号</div>
                                            <div>苏·X0202应急</div>
                                        </li>
                                        <li class="info-window-li">
                                             <div class="info-window-car">所属消防队</div>
                                            <div>特勤大队二中队</div>
                                         </li>
                                         <li class="info-window-li">
                                            <div class="info-window-car">随车消防员</div>
                                            <div>肖房</div>
                                         </li>
                                        <li class="info-window-li">
                                            <div class="info-window-car">联系方式</div>
                                             <div>18569458756</div>
                                        </li>
                                           <li class="info-window-li">
                                              <div class="info-window-car">状态</div>
                                             <div>待命</div>
                                        </li>
                                        <li class="info-window-li">
                                              <div class="info-window-car">一键呼叫</div>
                                             <div><img style="width: 0.24rem;height: 0.24rem;cursor: pointer;" src="../static/img/phone.png"></div>
                                        </li>
                                    </ul>
                                   </div>
                               </div>`;

        } else if (item == 'jhc') {
            marker.content = `<div style="width:4.5rem;height:2.4rem;">
                                <div class="info-window-tit">
                                       <img src="../static/img/xfc.png">
                                       救护车信息
                                   </div>
                                <div class="info-window-con" style="display: flex;">
                                       <div>
                                            <img src="../static/img/timg.jpg" style="margin-top: 0.14rem;">
                                     </div>
                                     <ul style="margin-top: 0.1rem;width: 2rem;margin-left: 0.16rem;">
                                        <li class="info-window-li">
                                             <div class="info-window-car">车牌号</div>
                                            <div>苏A OH166</div>
                                        </li>
                                        <li class="info-window-li">
                                             <div class="info-window-car">所属消防队</div>
                                            <div>栖霞区人民医院</div>
                                         </li>
                                         <li class="info-window-li">
                                            <div class="info-window-car">跟车医生</div>
                                            <div>尹苑</div>
                                         </li>
                                        <li class="info-window-li">
                                            <div class="info-window-car">联系方式</div>
                                             <div>18569458756</div>
                                        </li>
                                           <li class="info-window-li">
                                              <div class="info-window-car">状态</div>
                                             <div>待命</div>
                                        </li>
                                        <li class="info-window-li">
                                              <div class="info-window-car">一键呼叫</div>
                                             <div><img style="width: 0.24rem;height: 0.24rem;cursor: pointer;" src="../static/img/phone.png"></div>
                                        </li>
                                    </ul>
                                   </div>
                               </div>`;

        } else if (item == 'gcc') {
            marker.content = `<div style="width:4.5rem;height:2.4rem;">
                                <div class="info-window-tit">
                                       <img src="../static/img/xfc.png">
                                       工程车信息
                                   </div>
                                <div class="info-window-con" style="display: flex;">
                                       <div>
                                            <img src="../static/img/timsg.jpg" style="margin-top: 0.14rem;">
                                     </div>
                                     <ul style="margin-top: 0.1rem;width: 2rem;margin-left: 0.16rem;">
                                        <li class="info-window-li">
                                             <div class="info-window-car">车牌号</div>
                                            <div>苏A 1564O</div>
                                        </li>
                                        <li class="info-window-li">
                                             <div class="info-window-car">所属消防队</div>
                                            <div>特勤大队二中队</div>
                                         </li>
                                         <li class="info-window-li">
                                            <div class="info-window-car">随车工程师</div>
                                            <div>龚成</div>
                                         </li>
                                        <li class="info-window-li">
                                            <div class="info-window-car">联系方式</div>
                                             <div>18569458756</div>
                                        </li>
                                           <li class="info-window-li">
                                              <div class="info-window-car">状态</div>
                                             <div>待命</div>
                                        </li>
                                        <li class="info-window-li">
                                              <div class="info-window-car">一键呼叫</div>
                                             <div><img style="width: 0.24rem;height: 0.24rem;cursor: pointer;" src="../static/img/phone.png"></div>
                                        </li>
                                    </ul>
                                   </div>
                               </div>`;

        } else if (item == 'xfy') {
            marker.content = `<div style="width:3.4rem;height:2rem;">
                                            <div class="info-window-tit">
                                                <img src="../static/img/xfy.png">
                                                消防员信息
                                            </div>
                                            <div class="info-window-con">
                                                <ul style="margin-top: 0.1rem;">
                                                    <li class="info-window-li">
                                                        <div>姓名</div>
                                                        <div>肖房</div>
                                                    </li>
                                                    <li class="info-window-li">
                                                        <div>电话</div>
                                                        <div>18756542156</div>
                                                    </li>
                                                    <li class="info-window-li">
                                                        <div>所属消防队</div>
                                                        <div>南京市消防局特勤大队二中队</div>
                                                    </li>
                                                    <li class="info-window-li">
                                                        <div>状态</div>
                                                        <div>待命</div>
                                                    </li>
                                                    <li class="info-window-li">
                                                        <div>一键呼叫</div>
                                                        <div><img style="width: 0.24rem;height: 0.24rem;cursor: pointer;" src="../static/img/phone.png"></div>
                                                    </li>
                                                </ul>
                                            </div>
                                        </div>`;

        } else if (item == 'jzw') {
            marker.content = `<div style="width:10rem;height:5.6rem;">
                                <div class="info-window-tit">
                                    <img src="../static/img/xfz.png">
                                    建筑物详情 ———— 马群科创中心A栋 （消控室电话：83545698）
                                </div>
                                <div class="info-window-con" style="display: flex;margin-top: 0.2rem;">
                                    <img src="../static/img/buildbg.png">
                                </div>
                            </div>`;

        } else if (item == 'sy') {
            marker.content = `<div style="width:3.4rem;height:1.8rem;">
                                            <div class="info-window-tit">
                                                <img src="../static/img/sy.png">
                                                水源信息
                                            </div>
                                            <div class="info-window-con">
                                                <ul style="margin-top: 0.1rem;">
                                                    <li class="info-window-li">
                                                        <div>水源类型</div>
                                                        <div>室外消火栓</div>
                                                    </li>
                                                    <li class="info-window-li">
                                                        <div>地址</div>
                                                        <div>钟灵街与马高路交叉口向南200米</div>
                                                    </li>
                                                    <li class="info-window-li">
                                                        <div>水压</div>
                                                        <div>0.7MPa</div>
                                                    </li>
                                                    <li class="info-window-li">
                                                        <div>负责人电话</div>
                                                        <div>18954675954</div>
                                                    </li>
                                                </ul>
                                            </div>
                                        </div>`;
        } else {

            marker.content = `<div style="width:3.4rem;height:1.8rem;">
                                            <div class="info-window-tit">
                                                <img src="../static/img/sy.png">
                                                设备信息信息
                                            </div>
                                            <div class="info-window-con">
                                                <ul style="margin-top: 0.1rem;">
                                                    <li class="info-window-li">
                                                        <div>设备类型</div>
                                                        <div>${name}</div>
                                                    </li>
                                                    <li class="info-window-li">
                                                        <div>地址</div>
                                                        <div>江苏省南京市栖霞区学衡路14号</div>
                                                    </li>
                                                    <li class="info-window-li">
                                                        <div>设备状态</div>
                                                        <div>正常</div>
                                                    </li>
                                                    <li class="info-window-li">
                                                        <div>负责人电话</div>
                                                        <div>18954675954</div>
                                                    </li>
                                                </ul>
                                            </div>
                                        </div>`;
        }

        marker.on('click', function(e) {
            infoWindow.setContent(e.target.content);
            if (item == 'jzw') {
                infoWindow.open(map, [(map.getBounds().bounds[2].lng + map.getBounds().bounds[3].lng) / 2, (map.getBounds().bounds[2].lat + map.getBounds().bounds[3].lat) / 2]);

            } else {
                infoWindow.open(map, e.target.getPosition());
            }

        });
    }


    var isTraffic = false;

    function trafficToggle() {
        if (isTraffic) {
            trafficLayer.hide();
            isTraffic = false;
        } else {
            trafficLayer.show();
            isTraffic = true;
        }
    }


    // 加载地图上所有点资源
    function loadNodePoints() {
        var mapAppId = '';
        let orgAreaCode = JSON.parse(localStorage.getItem('isLogin')).roleAreaCode;
        var url = '/rest/firepm/global_node?areaCode=' + orgAreaCode + '&appid=' + mapAppId;
        $.ajax({
            url: url,
            type: "get",
            async: false,
            contentType: "application/json",
            success: function(result) {
                var result = eval("(" + result + ")");
                var data = result.ret.value;
                if (data == null) {
                    data = [];
                }
                setBuildsIntoMap(data, mapAppId);


            }
        })
    }
    /**/

    //地图建筑物
    var buildsGroup;
    var buildsArray = [];

    function setBuildsIntoMap(data, mapAppId) {
        map.remove(streetMarkers);

        buildsArray = [];
        $.each(data, function(index, el) {
            var buildMsg = '';
            el.west = bd_toGd(el.west, el.north).lng;
            el.north = bd_toGd(el.west, el.north).lat;
            var marker = new AMap.Marker({
                position: new AMap.LngLat(el.west, el.north),
                icon: '../static/img/_normal.png',
            }); // 创建点实例
            buildMsg = buildMsg + el.areaid + ",";
            if (el.count == 1) {
                //单个设备
                if (el.normal == 1) {
                    buildMsg = buildMsg + "正常," + el.areaname;
                    marker = new AMap.Marker({
                        position: new AMap.LngLat(el.west, el.north),
                        icon: '../static/img/_normal.png',
                    });
                } else if (el.issue == 1) {
                    buildMsg = buildMsg + "离线," + el.areaname;
                    marker = new AMap.Marker({
                        position: new AMap.LngLat(el.west, el.north),
                        icon: '../static/img/_issue.png',
                    });
                } else if (el.warn == 1) {
                    buildMsg = buildMsg + "报警," + el.areaname;
                    marker = new AMap.Marker({
                        position: new AMap.LngLat(el.west, el.north),
                        icon: '../static/img/_warn.png',
                    });
                }

                buildMsg = buildMsg + ',' + el.count + ',' + el.normal + ',' + el.bad + ',' + el.warn;
                marker.buildMsg = buildMsg;
                marker.on('click', function(e) {
                    setSelectNodeInfo(marker.buildMsg, '')

                });
            } else {
                //同一区域多个设备
                if (el.normal == el.count) {
                    buildMsg = buildMsg + "该建筑中的设备全部正常," + el.areaname;
                    marker = new AMap.Marker({
                        position: new AMap.LngLat(el.west, el.north),
                        icon: '../static/img/builds_normal.png',
                    });
                } else {
                    buildMsg = buildMsg + "该建筑存在异常设备," + el.areaname;
                    marker = new AMap.Marker({
                        position: new AMap.LngLat(el.west, el.north),
                        icon: '../static/img/builds_warn.png',
                    });
                }

                buildMsg = buildMsg + ',' + el.count + ',' + el.normal + ',' + el.warn + ',' + el.issue + ',' + el.areaheight + ',' + el.areatype + ',' + el.areadepth;
                marker.buildMsg = buildMsg;
                marker.on('click', function(e) {
                    setSelectNodeInfo(marker.buildMsg, '')

                });
            }


            buildsArray.push(marker);


        });
        buildsGroup = new AMap.OverlayGroup(buildsArray);
        map.add(buildsGroup);




    }
    //点击地图上设备触发事件
    function setSelectNodeInfo(nodeInfoString, mapAppId) {
        var nodeInfoArray = nodeInfoString.split(",");
        var address = nodeInfoArray[2];
        $('#b-address').html(address);
        //当所点击区域内设备数量大于1
        if (nodeInfoArray[3] > 1) {
            var level = nodeInfoArray[7];
            var floorurl = '/rest/firepm/global_floor_status?areaid=';
            var floorareaid = nodeInfoArray[0];


            var unlevel = nodeInfoArray[9];
            builds(level, floorurl, floorareaid, unlevel, mapAppId);
            getPreData(0, 5, '', floorareaid);

            $('#all-node').click(function(){
                getPreData(0, 5, '', floorareaid);
            })
        }
        //当所点击区域内设备数量等于1
        else {
            var url = '/rest/firepm/global_node_areaid?areaid=' + nodeInfoArray[0] + '&appid=' + mapAppId;
            $.ajax({
                url: url,
                type: "get",
                async: false,
                contentType: "application/json",
                success: function(result) {
                    var result = eval("(" + result + ")");
                    var data = result.ret.value;
                    $("#nodename").html(data[0].appname);
                    $("#nodeseuid").html(data[0].seuid);
                    $("#nodeorg").html(data[0].name);
                    $("#nodestatus").html(data[0].status);
                    $("#nodetime").html(data[0].time);
                    $("#nodeaddress").html(data[0].address);
                    //点击显示单个设备详情
                    $('.building-body-con-single').show();
                    $('.building-body-con-single-node').show();
                    $(".building").animate({ width: "100%", height: "100%", minHeight: "7.66rem" }, 500);

                }
            })
        }
    }
    //每栋楼数据
    function getPreData(from, count, floor, areaid) {
        count = 5;
        let mapAppId = ''
        $('.building-body-con-node-list').empty();
        var url = '/rest/firepm/global_floor_info?areaid=' + areaid + '&floor=' + floor + '&from=' + from + '&count=' + count + '&appid=' + mapAppId;
        if (floor == '') {
            $("#floornum").html('楼');

        } else {
            $("#floornum").html(floor);

        }
        $.ajax({
            url: url,
            type: "get",
            contentType: "application/json",
            success: function(result) {
                result = eval("(" + result + ")");
                var total = result.ret.total;
                if (0 == total % count) {
                    totalPage = parseInt(total / count);
                    if (totalPage == 0) totalPage = 1;
                } else {
                    totalPage = parseInt(total / count) + 1;
                }
                if (from === 0) {
                    currentPage = 1;
                }
                var data = result.ret.value;
                var url, projectname;
                let str = ''
                for (var i = 0; i < data.length; i++) {
                    if (data[i].appid == 1) {
                        projectname = '消火栓设备';
                        url = "frontPage/hydrant.html";
                    } else if (data[i].appid == 2) {
                        projectname = '喷淋末端设备';
                        url = "frontPage/sprinkler.html";
                    } else if (data[i].appid == 5) {
                        projectname = '消防水池水箱';
                        url = "frontPage/firebox.html";
                    } else if (data[i].appid == 6) {
                        projectname = '烟雾报警器';
                        url = "frontPage/smokemonitor.html";
                    } else if (data[i].appid == 7) {
                        projectname = '消防泵设备';
                        url = "frontPage/firepump.html";
                    } else if (data[i].appid == 9) {
                        projectname = '门磁设备';
                        url = "frontPage/firedoor.html";
                    } else if (data[i].appid == 16) {
                        projectname = '电气火灾抄表设备';
                        url = "frontPage/electric.html";
                    } else if (data[i].appid == 18) {
                        projectname = '电气火灾检测设备';
                        url = "electrfire/html/node.html";
                    } else if (data[i].appid == 19) {
                        projectname = '火灾自动报警主机';
                        url = data[i].euid;
                    } else if (data[i].appid == 20) {
                        projectname = '消防风机信息监测';
                        url = "frontPage/draught.html";
                    } else if (data[i].appid == 21) {
                        projectname = '消防泵信息监测';
                        url = "frontPage/pumpinfo.html";
                    } else if (data[i].appid == 22) {
                        projectname = '消防用水量监测';
                        url = "frontPage/waterater.html";
                    } else if (data[i].appid == 23) {
                        projectname = '可燃气体监测';
                        url = "frontPage/gas.html";
                    } else if (data[i].appid == 26) {
                        projectname = '通道占用监测';
                        url = "frontPage/geomagnetism.html";
                    } else if (data[i].appid == 27) {
                        projectname = '浸水监测';
                        url = "frontPage/soak.html";
                    } else if (data[i].appid == 28) {
                        projectname = '火眼监测';
                        url = "../../fireeye/";
                    } else if (data[i].appid == 29) {
                        projectname = '充电桩';
                        url = "../../fireeye/";
                    } else if (data[i].appid == 30) {
                        projectname = '温湿度监测';
                        url = "frontPage/hygrothermograph.html";
                    };
                    if (data[i].warningcode > 0) {

                        data[i].status = '设备报警';
                    }
                    status = data[i].status;
                    str = str + `     <div class="building-body-con-node-list-item">
                                <div class="building-body-con-node-list-item-top">
                                    <img src="../static/img/node1.png">${projectname}
                                    <img class="building-body-con-node-list-item-top-more" src="../static/img/more.png" onclick="gettheapp(\'` + data[i].appid + `\',\'` + url + `\')">
                                </div>
                                <div>
                                    <ul>
                                        <li>
                                            <span class="layui-badge-dot layui-bg-blue"></span>
                                            <span>${checkNullOrEmpty(status)}</span></li>
                                        <li>
                                            <span class="layui-badge-dot layui-bg-orange"></span>
                                            <span>${data[i].address}</span></li>
                                        <li>
                                            <span class="layui-badge-dot layui-bg-green"></span>
                                            <span>${data[i].name}</span></li>
                                    </ul>
                                </div>
                            </div>`
                }
                $(".building-body-con-node-list").append(str)
                $("#pagination").paginations({
                    currentPage: currentPage,
                    totalPage: totalPage,
                    callback: function(current) {
                        currentPage = current;
                        current = (current - 1) * count;
                        getPreData(current, count, floor, areaid);
                    }
                });

            }
        });
    }


    function clearMapInfo() {
        $('#panel').html('');
        $("input[type='radio']").each(function() {
            this.checked = false;
        });
        $("input[type='checkbox']").each(function() {
            if (this.id != 'lk') {
                this.checked = false;
            }

        });
        map.clearMap();

    }

    $('#pattern').click(function() {
        $('#pattern').hide();
        $('#satellite').show();
        satellite.show();
    })
    $('#satellite').click(function() {
        $('#satellite').hide();
        $('#pattern').show();
        satellite.hide();
    })




    /*当前报警信息*/

    function statusCurMsg() {

        var ROLL_SPEED = 100;
        var noticeList1 = $('#notice-list');
        var noticeList2 = $('#notice-list-2');
        var listWrapper = $('#list-wrapper');
        noticeList2.html(noticeList1.html())
        listWrapper.css('top', 0)
        var timer = setInterval(rollStart, ROLL_SPEED);

        function rollStart() {
            if (Math.abs(_subStr(listWrapper.css('top'))) >= noticeList1.height()) {
                listWrapper.css('top', 0)
            } else {
                var top = listWrapper.css('top');
                listWrapper.css('top', _subStr(top) - 1)
            }
        }
        // 截取px前数值
        function _subStr(str) {
            var index = str.indexOf('px');
            if (index > -1) {
                return parseFloat(str.substr(0, index + 1))
            }
        }

    }

    /*鼠标移动到街道上显示边界事件*/
    function street3DBoundary(name) {
        object3Dlayer = new AMap.Object3DLayer();
        map.add(object3Dlayer);
        ajax('../static/GJson/栖霞区.json', function(err, geoJSON) {
            if (!err) {
                var geojson = new AMap.GeoJSON({
                    geoJSON: geoJSON,
                    getPolygon: function(geojson, lnglats) {
                        if (name == geojson.properties.name) {
                            var bounds = lnglats[0].map(function(path) {
                                return new AMap.LngLat(path[0], path[1]);
                            });
                            var height = 2000;
                            var prism = new AMap.Object3D.Prism({
                                path: bounds,
                                height: height,
                                color: 'rgba(35, 124, 174,0.5)',
                            });

                            prism.transparent = true;
                            object3Dlayer.add(prism);
                        }

                    }
                });

            } else {}
        })
    }

    /*移除街道边界*/
    function clearStreet3DBoundary() {
        if (object3Dlayer != undefined) {
            map.remove(object3Dlayer);
        }
    }


    /*根据层级显示*/
    var isCollect = 1;

    function judgeWithZoom() {

        if (streetCode == "320113001") {
            var lng = 118.882574
            var lat = 32.122149

        } else if (streetCode == "320113002") {
            var lng = 118.891601
            var lat = 32.049522
        } else if (streetCode == "320113003") {
            var lng = 118.827274
            var lat = 32.111995
        } else if (streetCode == "320113004") {
            var lng = 118.843939
            var lat = 32.140956
        } else if (streetCode == "320113005") {
            var lng = 118.952702
            var lat = 32.152095
        } else if (streetCode == "320113006") {
            var lng = 119.123618
            var lat = 32.219791
        } else if (streetCode == "320113007") {
            var lng = 118.921384
            var lat = 32.099123
        } else if (streetCode == "320113010") {
            var lng = 119.002301
            var lat = 32.156414
        } else if (streetCode == "320113009") {
            var lng = 118.808658
            var lat = 32.192729
        } else {
            var lng = 118.998548
            var lat = 32.132001
        }



        if (isCollect == 0) {
            return;
        } else {
            let zoom = map.getZoom();
            if (zoom > 14) {
                var isCollectJu = 2;
                if (isCollect != isCollectJu) {
                    if (massLayer != undefined) {
                        map.remove(massLayer);
                    }
                    map.remove(streetMarkers);
                    //drawMassivePoint(lng, lat);
                    isCollect = 2;
                    clearStreet3DBoundary();
                }
            } else {
                var isCollectJu = 1;
                if (isCollect != isCollectJu) {
                    if (massLayer != undefined) {
                        map.remove(massLayer);
                    }
                    map.remove(streetMarkers);
                    streetNodeNumber()
                    isCollect = 1;
                    qiXia3DBoundary();
                }
            }
        }

    }

    /*绘制海量点*/
    var massMarkers, massLayer;

    function drawMassivePoint(lng, lat) {
        // 创建 AMap.LabelsLayer 图层
        massLayer = new AMap.LabelsLayer({
            zIndex: 1000,
            animation: false,
            collision: false
        });

        // 将图层添加到地图
        map.add(massLayer);


        massMarkers = [];


        for (var i = 0; i < 2000; i++) {
            var iconType = Math.floor(Math.random() * (5 - 1)) + 1
            if (iconType == 1) {
                var icon = {
                    type: 'image',
                    clipOrigin: [0, 0],
                    image: '../static/img/hydrant.png',
                    size: [24, 24],
                    anchor: 'center',
                    angel: 0,
                    retina: true
                };

            } else if (iconType == 2) {
                var icon = {
                    type: 'image',
                    clipOrigin: [0, 0],
                    image: '../static/img/builds_warn.png',
                    size: [24, 24],
                    anchor: 'center',
                    angel: 0,
                    retina: true
                };

            } else if (iconType == 3) {
                var icon = {
                    type: 'image',
                    clipOrigin: [0, 0],
                    image: '../static/img/firedoor.png',
                    size: [24, 24],
                    anchor: 'center',
                    angel: 0,
                    retina: true
                };

            } else if (iconType == 4) {
                var icon = {
                    type: 'image',
                    clipOrigin: [0, 0],
                    image: '../static/img/waterconsumption.png',
                    size: [24, 24],
                    anchor: 'center',
                    angel: 0,
                    retina: true
                };

            }

            var curData = {
                position: [lng + (Math.random() - 0.5) / 15, lat + (Math.random() - 0.5) / 15],
                icon
            };

            var labelMarker = new AMap.LabelMarker(curData);

            massMarkers.push(labelMarker);

        }
        massLayer.add(massMarkers);
        // 普通点
        var normalMarker = new AMap.Marker({
            offset: new AMap.Pixel(-75, -40),
        });
        // 事件
        massLayer.on('mouseover', function(e) {
            var position = e.data.data && e.data.data.position;

            if (position) {
                normalMarker.setContent(
                    `<div id="marker-node-msg">${position}</div>  `);
                normalMarker.setPosition(position);
                map.add(normalMarker);
            }
        });
        massLayer.on('mouseout', function() {
            map.remove(normalMarker);
        });

    }


    /*关闭建筑物详情*/
    $('#building-close').click(function() {
        $(".building").animate({ width: "0px", height: "0px", minHeight: "0px" }, 500, function() {
            $("#demo").html('');
            $("#demo").css('bottom',"");
            $('.building-body-con-single').hide();
            $('.building-body-con-model').hide();
            $('.building-body-con-node').hide();
            $('.building-body-con-single-node').hide();

            $(".building-body-con-node-list").html('');
        })
    })